package com.liuheng.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liuheng.manager.service.BrandService;
import com.liuheng.spzx.model.entity.product.Brand;
import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<Brand>> listBrand(@PathVariable("page") int pageSize, @PathVariable int limit){
        Page page = new Page(pageSize, limit);
        Page pageInfo = brandService.page(page);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result saveBrand(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/update")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteBrand(@PathVariable Long id){
        brandService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/findAll")
    public Result findAllBrand(){
        List<Brand> list = brandService.list();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
